//
//  LJHPlayListViewController.m
//  HEARME
//
//  Created by mac on 16/2/24.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "LJHPlayListViewController.h"
#import "LJHPlayListTableViewCell.h"
@interface LJHPlayListViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)LJHBaseTableView *listTableView;

@end

@implementation LJHPlayListViewController
- (void)dealloc
{
    [_listTableView release];
    [_playArray release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createTableView];
  
    // Do any additional setup after loading the view.
}
-(void)createTableView
{
   
    self.listTableView = [[LJHBaseTableView alloc] initWithFrame:CGRectMake(0, 20, WIDTH, HEIGHT-64) style:UITableViewStylePlain];
    [self.view addSubview:self.listTableView];
    [_listTableView release];
    self.listTableView.dataSource = self;
    self.listTableView.delegate = self;
    [self.listTableView registerClass:[LJHPlayListTableViewCell class] forCellReuseIdentifier:@"playListTableCell"];
    [self.listTableView reloadData];
    self.listTableView.bounces = NO;
    
    LJHBaseButton *backBtn = [[LJHBaseButton buttonWithType:UIButtonTypeCustom] autorelease];
    backBtn.frame = CGRectMake(0, self.listTableView.frame.size.height, WIDTH, HEIGHT-self.listTableView.frame.size.height);
    [backBtn setTitle:@"返回到播放页面" forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
    
     LJHBaseView *headView = [[LJHBaseView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30)];
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,10,10) ];
    arrowImageView.backgroundColor = [UIColor clearColor];
    arrowImageView.image = [UIImage imageNamed:@"findsection_logo@2x.png"];
    [headView addSubview:arrowImageView];
    [arrowImageView release];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(arrowImageView.frame.origin.x + arrowImageView.frame.size.width + 10, arrowImageView.frame.origin.y-5, 200, 20)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text = self.kind;
    [headView addSubview:titleLabel];
    [titleLabel release];
    
    self.listTableView.tableHeaderView = headView;

    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _playArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    LJHPlayListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"playListTableCell"];
    
    LJHTrackModel *model = [self.playArray objectAtIndex:indexPath.row];
    LJHChildListModel *historyModel = [self.playArray objectAtIndex:indexPath.row];
    cell.newsTitle.text = model.title;
    [cell.newsPic sd_setImageWithURL:[NSURL URLWithString:model.coverSmall] placeholderImage:[UIImage imageNamed:@"1024"]];
    if ([_kind isEqualToString:@"播放历史"]) {
        [cell.newsPic sd_setImageWithURL:[NSURL URLWithString:historyModel.coverPath] placeholderImage:[UIImage imageNamed:@"1024"]];
    }
    return cell;
}

//-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return SCREEN_HEIGHT*0.01;
//}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return WIDTH*0.14;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LJHTrackModel *model = [self.playArray objectAtIndex:indexPath.row];
    [LJHPlayerViewController sharaMusicPlayer].song_id = model.trackId;
    [LJHPlayerViewController sharaMusicPlayer].allMusicArray = self.playArray;
    [LJHPlayerViewController sharaMusicPlayer].indexRow = indexPath.row;
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
-(void)backBtnAction:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self removeFromParentViewController];
    [self.view removeFromSuperview];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
